<%@ page contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ include file="/common/init.jsp"%>
<link href="<c:url value='/admin/css/custom.css'/>" rel="stylesheet" type="text/css" />
<link href="<c:url value='/admin/css/style.css'/>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<c:url value='/resources/js/jquery-1.7.2.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/resources/js/validate.js'/>"></script>
<script type="text/javascript">
$(function(){
	$("#lookAccount").click(function(){
		var time = new Date();
		var account = $("#account").val();
		if($.trim(account) == ''){
			alert("会员ID为空!");
			return ;
		}
		window.showModalDialog('${ctx}/admin/useraccount.action?account='+account+'&time='+time,window,'dialogWidth:500px;dialogHeight:350px;center:yes;help:yes;status:no');
		
	});
	
	/* $("#querybtnlist").click(function(){
		var data = $("#chargeFrmList").serialize();
		alert(data);
		jQuery.ajax({
			url: "${ctx}/admin/charge.action",
			type: "post",
			dataType:"html",
			data: data,
	        async:false,  // 设置同步方式
	        cache:false,
			success: function(jsondata){
				$("#chargelistdiv").html(jsondata);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
		    }
		});
	}); */
});
	function doCharge(){
		$.ajaxSetup({cache:false});
		var checkFlg = true;
		checkFlg = checkFlg && validateEmpty_jquery("会员ID", "account");
		$.ajax({
			type:'POST',
			url: "${ctx}/chkUExsit.action",
			data: "account="+$("#account").val(),
	        async:false,  // 设置同步方式
	        cache:false,
			dataType:"html",
			success: function(data,status){
				if($.trim(data)!=''){
					setValidateErrorStyle_jquery($("#account"));
					alert(data);
					checkFlg = checkFlg && false;
				}
			},
			error: function(data,status,e){
				alert(e.name);
			}
		});
		checkFlg = checkFlg && validateEmpty_jquery("金额 ", "chargeAmount");
		checkFlg = checkFlg && validateNumber_jquery("金额 ", "chargeAmount");
		checkFlg = checkFlg && validateEmpty_jquery("您的三级密码", "thirdPassword");
		//checkFlg = checkFlg && false;
		$.ajax({
			type:'POST',
			url: "${ctx}/admin/chkthid.action",
			data: "thirdPassword="+$("#thirdPassword").val(),
	        async:false,  // 设置同步方式
	        cache:false,
			dataType:"html",
			success: function(data,status){
				if($.trim(data)!=''){
					setValidateErrorStyle_jquery($("#thirdPassword"));
					alert(data);
					checkFlg = checkFlg && false;
				}
			},
			error: function(data,status,e){
				alert(e.name);
			}
		});
		//alert(checkFlg);
		if ( !checkFlg ) return false;
	    if (checkFlg) {
	    	$("#button").val("提交中");
			$("#button").attr("disabled","disabled");
	    	var data = $("#chargeForm").serialize();
	    	//alert(data);
			jQuery.ajax({
				url: "${ctx}/admin/docharge.action",
				type: "post",
				dataType:"html",
				data:data,
		        async:false,  // 设置同步方式
		        cache:false,
				success: function(jsondata){
					alert(jsondata);
					self.location.href = "${ctx}/admin/charge.action";
				},
				error: function(XMLHttpRequest, textStatus, errorThrown) {
			    }
			});
	    }
	}
	//alert($("#chargeFrm").serialize());
	function frontpage(pageNo){
		/* jQuery.ajax({
			url: "${ctx}/admin/chargelist.action?pageNo="+pageNo,
			type: "post",
			dataType:"html",
			data: $("#chargeFrmList").serialize(),
	        async:false,  // 设置同步方式
	        cache:false,
			success: function(jsondata){
				$("#chargelistdiv").html(jsondata);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
		    }
		}); */
		
		location = "${ctx}/admin/charge.action?pageNo="+pageNo+"&"+$("#chargeFrmList").serialize();
	}

	function nextpage(pageNo){
		/* jQuery.ajax({
			url: "${ctx}/admin/chargelist.action?pageNo="+pageNo,
			type: "post",
			dataType:"html",
			data: $("#chargeFrmList").serialize(),
	        async:false,  // 设置同步方式
	        cache:false,
			success: function(jsondata){
				$("#chargelistdiv").html(jsondata);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
		    }
		}); */
		location = "${ctx}/admin/charge.action?pageNo="+pageNo+"&"+$("#chargeFrmList").serialize();
	}
</script>
<style type="text/css">
<!--
body {
	background: #ffffff;
	margin-top:10px;
	margin-left:5px;
	margin-right:5px;
}
-->
</style>
<body>
<div class="EpmsSubTitle"><p><b>会员充值/扣款</b></p>
</div>
<form method="post" id="chargeForm"> 
<input type="hidden" id="userId" name="userId" value="${admin.userId}">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="EpmsTable">
	<tr>
		<td class=EpmsTdTitle width="15%"><b>会员ID</b></td>
		<td class="EpmsTdNoColor" width="85%">
			<input type="text" id="account" name="account" value="${account}" style="width: 20%"/><font color="red"> *</font>
			<input type="button" id="lookAccount" value="查看账户余额"/>
		</td>
	</tr>
	<tr>
		<td class=EpmsTdTitle>类型</td>
		<td class="EpmsTdNoColor">
			<select name="chargeType" id="chargeType" style="width: 20%">
				<c:forEach var="charge" items="${chargeList}">
					<option value="${charge.code}">${charge.name}</option>
				</c:forEach>
				<!-- <option value="1">充值</option>
				<option value="2">扣款</option> -->
			</select><font color="red"> *</font>
		</td>
	</tr>
	<tr>
		<td class=EpmsTdTitle>会计科目</td>
		<td class="EpmsTdNoColor">
			<select name="accountType" id="accountType" style="width: 20%">
				<c:forEach var="accoun" items="${accountSubList}">
					<option value="${accoun.code}">${accoun.name}</option>
				</c:forEach>
				<!-- <option value="1">激活豆</option>
				<option value="2">咖啡豆</option>
				<option value="3">游戏豆</option>
				<option value="4">仙草豆</option>
				<option value="5">VV豆</option> -->
			</select><font color="red"> *</font>
		</td>
	</tr>
	<tr>
		<td class=EpmsTdTitle>金额</td>
		<td class="EpmsTdNoColor">
			<input type="text" id="chargeAmount" name="chargeAmount" value="" style="width: 20%"/><font color="red"> *</font>
		</td>
	</tr>
	<tr>
		<td class=EpmsTdTitle>说明</td>
		<td class="EpmsTdNoColor">
			<input type="text" id="remark" name="remark" value="" style="width: 60%"/>
		</td>
	</tr>
	<tr>
		<td class=EpmsTdTitle>您的三级密码</td>
		<td class="EpmsTdNoColor">
			<input type="password" id="thirdPassword" name="thirdPassword" value="" style="width: 20%"/><font color="red"> *</font>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center">
			<input type="button" name="button" id="button" value="提交" class="inputSubmit" onclick="doCharge();"/>
		</td>
	</tr>
</table>
</form>
<div class="EpmsInall">
<div class="EpmsSubTitle"><p><b>查询条件</b></p>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="EpmsTable">
<form action="charge.action" method="post" id="chargeFrmList">
	<tr>
    <td width="10%" class="EpmsTdWithColor">
    	<span class="portlet-section-header">会员ID</span></td>
	<td width="15%" class="EpmsTdNoColor">
	 	<input type="text" name="account" value="${account}"  id="projectName" class=inputInput/>
	</td> 
    <td width="10%" class="EpmsTdWithColor">
    	<span class="portlet-section-header">会计科目</span></td> 
	<td width="15%" class="EpmsTdNoColor" >
		<select name="accountType" id="accountType">
			<option value="">全部</option>
			<c:forEach var="account" items="${accountList}">
				<option value="${account.code}" <c:if test="${account.code eq accountType}"></c:if>>${account.name}</option>
			</c:forEach>
		</select>
	</td>
	<td width="10%" class="EpmsTdWithColor">
    	<span class="portlet-section-header">类型</span></td> 
	<td width="15%" class="EpmsTdNoColor" >
		<select name="subjectType" id="subjectType">
			<option value="">全部</option>
			<c:forEach var="charge" items="${chargeList}">
				<option value="${charge.name}" <c:if test="${charge.name eq subjectType}"></c:if>>${charge.name}</option>
			</c:forEach>
		</select>
	</td>
	<td class="EpmsTdNoColor" align="center">
		<div class="EpmsButtonDiv">&nbsp;
		  <input type="submit" name="button" id="querybtnlist" value="查询" class="inputSubmit" />
		  <input type="reset" name="button" id="button" value="清空" class="inputSubmit" />
		</div>
	</td>
    </tr>
</form>
</table>
</div>
<div id="chargelistdiv">
<div class="EpmsSubTitle"><p><b>会员列表</b></p>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="EpmsTable">
  <tr>
	  <td class=EpmsTdTitle>序号</td>
	  <td class=EpmsTdTitle>会员ID</td>
	  <!-- <td class=EpmsTdTitle>会计科目</td> -->
	  <td class=EpmsTdTitle>类型</td>
	  <td class=EpmsTdTitle>收入</td>
	  <td class=EpmsTdTitle>支出</td>
	  <td class=EpmsTdTitle>时间</td>
  </tr>
	<c:forEach var="money" items="${page.result }" varStatus="status">
		<tr>
			<td class=EpmsTdNoColor >${status.count}&nbsp;</td>
		    <td class=EpmsTdNoColor >${money.remark}&nbsp;</td>
		    <%-- <td class=EpmsTdNoColor >${money.accountType}&nbsp;</td> --%>
			<td class=EpmsTdNoColor >${money.accountSubject}&nbsp;</td>
			<td class=EpmsTdNoColor >${money.income}&nbsp;</td>
			<td class=EpmsTdNoColor >${money.pay}&nbsp;</td>
			<td class=EpmsTdNoColor>
				<fmt:formatDate value="${money.createDate}" pattern="yyyy-M-dd HH:mm:ss"/>&nbsp;
			</td>
		</tr>
	</c:forEach>
	<tr>
		<td class="EpmsTdNoColor" colspan="11" align="right">
		第${page.pageNo}页&nbsp;&nbsp;
			<c:choose>
			<c:when test="${page.pageNo >1}">
				<a href="javascript:void(0);" style="text-decoration: none;">
					<span onclick="frontpage(${page.pageNo-1})">上一页</span>&nbsp;
				</a>
			</c:when>
			<c:otherwise>
				上一页 &nbsp;
			</c:otherwise>
			</c:choose>
			<c:choose>
				<c:when test="${page.totalPageCount > page.pageNo}">	
					<a href="javascript:void(0);" style="text-decoration: none;">
						<span onclick="nextpage(${page.pageNo+1})">下一页</span> &nbsp;
					</a>
				</c:when>
				<c:otherwise>
					下一页&nbsp;
				</c:otherwise>
			</c:choose>
			&nbsp;共${page.totalPageCount }页
		</td>
	</tr>
</table>
</div>
</div>
</body>